package com.sun.springbootspi;

import com.sun.springbootspi.service.Logger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import java.util.ServiceLoader;

@SpringBootApplication
public class SpringbootSpiApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootSpiApplication.class, args);
    }

    @Bean
    public Logger[] loggers() {
        ClassLoader classLoader = SpringbootSpiApplication.class.getClassLoader();
        ServiceLoader<Logger> serviceLoader = ServiceLoader.load(Logger.class, classLoader);
        return serviceLoader.stream().map(ServiceLoader.Provider::get).toArray(Logger[]::new);
    }

}
